﻿@model thailandProject.Models.Pair<thailandProject.Models.EMAILPREFERENCE, bool>

@{
    ViewBag.Title = "Edit Email Preferences";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
            @Html.ActionLink("Back to Index", "Index")
            <br /><br />
            @if (Model.value2)
            {
                <p style="color:red;">Thank you. Your preferences have been updated.</p>
            }
            <fieldset>
                <legend>PREFERENCES INFORMATION</legend>
                The following fields will allow you to customize how the system manages sending emails. Whenever the specified event happens,
                the system will send an email to the client. Check the description below the checkbox for information on what each event entails.
                <br /><br />
                The gmail username and password fields allow you to specify which gmail account is used when the system sends out an email. All user
                accounts share the same gmail account for consistency. Upon changing the account information, a confirmation message will be sent to
                the entered account.
            </fieldset>
            <br />
            @using(Html.BeginForm("EmailPreferences", "Admin", FormMethod.Post, new { id = "editForm" }))
            {
                string onPropInquiry = Model.value1.onPropInquiry ? "checked=\"checked\"" : "";
                string onDepositMade = Model.value1.onDeposityMade ? "checked=\"checked\"" : "";
                string onRefundMade = Model.value1.onRefundMade ? "checked=\"checked\"" : "";
                string onReservationDrop = Model.value1.onReservationDrop ? "checked=\"checked\"" : "";
                string onReservationEdit = Model.value1.onReservationEdit ? "checked=\"checked\"" : "";
                <div id="searchcontainer">
                <div class="display-label">On Property Inquiry</div>
                <div class="display-field">
                    <input type="hidden" name="userID" value="@Model.value1.userID" />
                    <input type="checkbox" name="onPropInquiry" @onPropInquiry />
                    <p>Sends an email to a client after selecting properties and pressing the email button. Disabling this will
                        still show the email text, but will not send the email.
                    </p>
                    @Html.ActionLink("Edit On Property Inquiry Template...", "EditEmailTemplate", new { type = "onPropInquiry" })
                </div>
                <div class="display-label">On Deposit Made</div>
                <div class="display-field">
                    <input type="checkbox" name="onDepositMade" @onDepositMade />
                    <p>Sends an email to a client after submitting a deposit on a currently held reservation. Provides information
                        such as the amount deposited and the remaining balance.
                    </p>
                    @Html.ActionLink("Edit On Deposit Made Template...", "EditEmailTemplate", new { type = "onDepositMade" })
                </div>
                <div class="display-label">On Refund Made</div>
                <div class="display-field">
                    <input type="checkbox" name="onRefundMade" @onRefundMade />
                    <p>Sends an email to a client after deleting a payment. Provides information on the amount refunded.
                    </p>
                    @Html.ActionLink("Edit On Refund Made Template...", "EditEmailTemplate", new { type = "onRefundMade" })
                </div>
                <div class="display-label">On Reservation Drop</div>
                <div class="display-field">
                    <input type="checkbox" name="onReservationDrop" @onReservationDrop />
                    <p>Sends an email to a client notifying them that their reservation has been dropped because another client
                        made a deposit before they did.
                    </p>
                    @Html.ActionLink("Edit On Reservation Drop Template...", "EditEmailTemplate", new { type = "onReservationDrop" })
                </div>
                <div class="display-label">On Reservation Edit</div>
                <div class="display-field">
                    <input type="checkbox" name="onReservationEdit" @onReservationEdit />
                    <p>Sends an email to a client notifying them that their reservation has been modified. This will explain
                        the changes made.
                    </p>
                    @Html.ActionLink("Edit On Reservation Edit Template...", "EditEmailTemplate", new { type = "onReservationEdit" })
                </div>
                <br />
                <div class="display-label">Gmail Username</div>
                <div class="display-field">
                    <input type="text" id="gmailUserName" name="gmailUserName" value="@Model.value1.gmailUserName" maxlength="50" />
                </div>
                <div class="display-label">Gmail Password</div>
                <div class="display-field">
                    <input type="password" id="gmailPassword" name="gmailPassword" value="@Model.value1.gmailPassword" maxlength="50" />
                </div>
                <div class="formButtons">
                    <input type="image" src="../../images/save_button.png" id="addTaskTypeButton" value="Save User" />
                    <div id="gmailError1" style="color:red; visibility:hidden">If a username is entered, a password must be entered as well</div>
                    <div id="gmailError2" style="color:red; visibility:hidden">If a password is entered, a username must be entered as well</div>
                </div>
            </div>
            }
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script type = "text/javascript">
    $("#editForm").submit(function () {

        var isValid = true;

        var username = $("#gmailUserName").val();
        var password = $("#gmailPassword").val();

        if (username != "" && password == "") {
            $("#gmailUserName").focus();
            $("#gmailError1").attr('style', 'color:red; visibility:visible;');
            $("#gmailError2").attr('style', 'color:red; visibility:hidden;');
        }
        else if (username == "" && password != "") {
            $("#gmailPassword").focus();
            $("#gmailError2").attr('style', 'color:red; visibility:visible;');
            $("#gmailError1").attr('style', 'color:red; visibility:hidden;');
        }
        else {
            //Both or no fields have something in them
            $("#gmailError1").attr('style', 'color:red; visibility:hidden;');
            $("#gmailError2").attr('style', 'color:red; visibility:hidden;');
            return true;
        }

        return false;
    })
</script>
